package com.teacherprofile.web.controller.system;

import com.teacherprofile.common.annotation.RateLimiter;
import com.teacherprofile.common.core.domain.AjaxResult;
import com.teacherprofile.common.domain.SysUserDetails;
import com.teacherprofile.common.enums.LimitType;
import com.teacherprofile.system.service.ISysUserDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 个人详情信息管理
 */

@Api(tags = "用户个人信息详情")
@RestController
@RequestMapping("/system/user/details")
public class SysUserDetailsController {
    @Autowired
    private ISysUserDetailsService detailsService;

    /**
     * 获取个人详情，qps超过50开启限流策略
     * @return
     */
    @ApiOperation("获取用户个人信息详情")
    @GetMapping
    @RateLimiter(key = "details",count = 50,time = 1, limitType = LimitType.IP)
    public AjaxResult getUserDetails() {
        return AjaxResult.success(detailsService.getUserDetails());
    }

    @ApiOperation("保存用户个人信息详情")
    @PostMapping
    public AjaxResult save(@RequestBody SysUserDetails sysUserDetails) {
        return AjaxResult.success(detailsService.insertSysUserDetails(sysUserDetails));
    }

    @ApiOperation("更新用户个人信息详情")
    @PutMapping
    public AjaxResult update(@RequestBody SysUserDetails sysUserDetails) {
        return AjaxResult.success(detailsService.updateSysUserDetails(sysUserDetails));
    }
}
